home *** CD-ROM | disk | FTP | other *** search
- Path: news.iastate.edu!usenet
- From: Steve Lee <sjlee@iastate.edu>
- Newsgroups: comp.lang.c++
- Subject: const wasting space and slower?
- Date: Sun, 18 Feb 1996 22:12:43 -0800
- Organization: Iowa State University
- Message-ID: <312814DB.399F@iastate.edu>
- NNTP-Posting-Host: dial61.ppp.iastate.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6b (Win16; I)
-
- Hi,
-
- I know this debate has been discussed numerous times on this newsgroup (whether to use const or
- #define for constants in C++), but I've never seen an answer for this question I just thought of.
- I know one benefit of using const is that you get type checking. But here is my question...
-
- When you declare something like this:
-
- const int MAX_FILES = 20;
-
- doesn't the compiler reserve global, read-only memory for this variable? Or does it just replace
- instances in the source code where MAX_FILES is found and replaces it with 20, similar to a
- preprocessor, but with typechecking? Also, if the compiler does place it in memory, do
- instructions then reference the memory, instead of immediate addressing mode?
-
- If this is so, I think it wastes space (storage of constants) and is slower (direct addressing
- mode vs. immediate addressing mode).
-
- --
- Steve Lee
- Computer Engineering/Computer Science
- Iowa State University
- email -> sjlee@iastate.edu
- WWW -> http://www.cs.iastate.edu/~sjlee/homepage.html
-